package image;

import mllib.*;
import java.util.Scanner;
import java.io.*;

public class ImageClassifierTester
{
  public static void main(String args[])
  {
    if(args.length < 2)
    {
      System.err.println("args: trainingfile [pcafile] testingfile");
      System.exit(1);
    }

    String pcaFilename = null;
    String trainingFilename = args[0];
    String testingFilename = null;
    if(args.length == 2)
    {
      testingFilename = args[1];
    }
    else
    {
      pcaFilename = args[1];
      testingFilename = args[2];
    }
    Classifier classifier = new Classifier(trainingFilename, pcaFilename, 60);
    Scanner sc = null;

    try
    {
      sc = new Scanner(new File(testingFilename));
    }
    catch(FileNotFoundException e)
    {
      e.printStackTrace();
      System.exit(1);
    }

    int dim = sc.nextInt();
    sc.nextLine();
    
    while(sc.hasNextLine() )
    {
      String realWord = sc.next();
      double[] v = new double[dim];
      for( int i = 0; i < dim; i++) {
          v[i] = sc.nextDouble();
      }
      sc.nextLine();
      System.out.println("Classified " + realWord + " as " + classifier.identify( v));
    }
  }
}
